package com.ad.pet.ui;

import android.app.Dialog;
import android.content.Context;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ad.pet.R;

/**
 * 忘记密码
 * Created by SEELE on 2018/3/22.
 */

public class TipsDialogView extends Dialog {
    OnLotteryLinstener onLotteryLinstener;
    private int screenWidth;
    private EditText mEtEmail;
    private EditText mEtPwd;
    private EditText mEtCode;
    private TextView mBtnCode;
    private ImageView mIvSetPwdEye;

    public TipsDialogView(Context context, int themeResId) {
        super(context, themeResId);
        screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        initView(context);
    }



    private void initView(Context context){
        View view = View.inflate(context, R.layout.layout_msg_loading_dialog,null);
        Button btnSure =  view.findViewById(R.id.Btton);
        ImageView imageViewClose =  view.findViewById(R.id.iv_close);
        mEtEmail = view.findViewById(R.id.et_regist_email);
        mEtPwd = view.findViewById(R.id.et_regsit_pwd);
        mEtCode = view.findViewById(R.id.et_code);
        mBtnCode = view.findViewById(R.id.btn_code);
        mIvSetPwdEye = view.findViewById(R.id.iv_set_pwd_eye);


        setContentView(view);
        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (screenWidth *  8/ 10); // 设置宽度
        this.getWindow().setAttributes(lp);
        window.setGravity(Gravity.CENTER);
        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onLotteryLinstener!=null)
                    onLotteryLinstener.onSure();
            }
        });
        imageViewClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setEye(false);

    }
    public interface OnLotteryLinstener{
        void onSure();
    }

    public EditText getEtEmail() {
        return mEtEmail;
    }

    public EditText getEtPwd() {
        return mEtPwd;
    }

    public EditText getEtCode() {
        return mEtCode;
    }

    public TextView getBtnCode() {
        return mBtnCode;
    }

    public void setOnLotteryLinstener(OnLotteryLinstener onLotteryLinstener) {
        this.onLotteryLinstener = onLotteryLinstener;
    }

    public void setEye(boolean isEye) {

        if (isEye) {
            mIvSetPwdEye.setImageResource(R.drawable.ic_eye);
            mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        } else {
            mIvSetPwdEye.setImageResource(R.drawable.ic_uneye);
            mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }

    }

    public ImageView getIvSetPwdEye() {
        return mIvSetPwdEye;
    }

    public void  clearData(){
        mEtEmail.setText("");
        mEtCode.setText("");
        mEtPwd.setText("");
    }
}
